using System;
using System.Timers;

namespace Halide
{
	/// <summary>
	/// Accurate, Simple, and Easy to use Stopwatch Class. This class
	/// can be used to track process execution time in seconds and milliseconds.
	/// </summary>
	/// <example>
	/// Sample usage:
	/// <code>
	/// Halide.StopWatch sw = new Halide.StopWatch();
	/// sw.Start();
	/// 
	/// Trace.Write("Stopwatch", "Process1:" sw.GetTime());
	/// Trace.Write("Stopwatch", "Process2:" sw.GetTime());
	/// sw.Stop()
	/// 
	/// Trace.Write("Stopwatch", "Process 1 &amp; 2:" sw.GetTime());
	/// </code>
	/// </example>
	public class StopWatch
	{
		private static string _version = "2008.02.08A";

		/// <summary>
		/// Return the version number of the class; read-only.
		/// </summary>
		/// <value>
		/// String version number of the class.
		/// </value>
		public static string Version
		{
			get
			{
				return _version;
			}
		}
		
		private int _StartTime;
	    private int _StopTime;

	    private int StartTime
	    {
	        get
	        {
	            return this._StartTime;
	        }
	        set
	        {
	            this._StartTime = value;
	        }
	    }

	    private int StopTime
	    {
	        get
	        {
	            return this._StopTime;
	        }
	        set
	        {
	            this._StopTime = value;
	        }
	    }

		/// <summary>
		/// Initializes the StopWatch to 0.
		/// </summary>
		/// <example>
		/// Sample usage:
		/// <code>
		/// Halide.StopWatch sw = new Halide.StopWatch();
		/// sw.Start();
		/// 
		/// Trace.Write("Stopwatch", "Process1:" sw.GetTime());
		/// Trace.Write("Stopwatch", "Process2:" sw.GetTime());
		/// sw.Stop()
		/// 
		/// Trace.Write("Stopwatch", "Process 1 &amp; 2:" sw.GetTime());
		/// </code>
		/// </example>
		public StopWatch()
	    {
	        StartTime = 0;
	        StopTime = 0;
	    }

		/// <summary>
		/// Starts the Stopwatch.
		/// </summary>
		/// <example>
		/// Sample usage:
		/// <code>
		/// Halide.StopWatch sw = new Halide.StopWatch();
		/// sw.Start();
		/// 
		/// Trace.Write("Stopwatch", "Process1:" sw.GetTime());
		/// Trace.Write("Stopwatch", "Process2:" sw.GetTime());
		/// sw.Stop()
		/// 
		/// Trace.Write("Stopwatch", "Process 1 &amp; 2:" sw.GetTime());
		/// </code>
		/// </example>
		public void Start()
	    {
	        StartTime =
	            DateTime.Now.Hour * 60 * 60 * 1000 +
	            DateTime.Now.Minute * 60 * 1000 +
	            DateTime.Now.Second * 1000 +
	            DateTime.Now.Millisecond;
	        //Console.WriteLine("StartTime: " + StartTime);
	    }

		/// <summary>
		/// Stops the Stopwatch.
		/// </summary>
		/// <example>
		/// Sample usage:
		/// <code>
		/// Halide.StopWatch sw = new Halide.StopWatch();
		/// sw.Start();
		/// 
		/// Trace.Write("Stopwatch", "Process1:" sw.GetTime());
		/// Trace.Write("Stopwatch", "Process2:" sw.GetTime());
		/// sw.Stop()
		/// 
		/// Trace.Write("Stopwatch", "Process 1 &amp; 2:" sw.GetTime());
		/// </code>
		/// </example>
		public void Stop()
	    {
	        StopTime =
	            DateTime.Now.Hour * 60 * 60 * 1000 +
	            DateTime.Now.Minute * 60 * 1000 +
	            DateTime.Now.Second * 1000 +
	            DateTime.Now.Millisecond;
	        //Console.WriteLine("StopTime: " + StopTime);
	    }

		/// <summary>
		/// Reset the Stopwatch to 0.
		/// </summary>
		/// <example>
		/// Sample usage:
		/// <code>
		/// Halide.StopWatch sw = new Halide.StopWatch();
		/// sw.Start();
		/// 
		/// Trace.Write("Stopwatch", "Process1:" sw.GetTime());
		/// sw.Reset();
		/// Trace.Write("Stopwatch", "Process2:" sw.GetTime());
		/// sw.Stop()
		/// 
		/// Trace.Write("Stopwatch", "Process 1 &amp; 2:" sw.GetTime());
		/// </code>
		/// </example>
		public void Reset()
	    {
	        StartTime = DateTime.Now.Millisecond;
	        StopTime = DateTime.Now.Millisecond;
	    }

		/// <summary>
		/// Returns a string containing the elasped time since the Start
	    /// of the StopWatch.
	    /// <para>(If Called after the Stop Method)
	    /// Returns a string containing the elasped time between the Start
	    /// of the StopWatch and the Stop of the  StopWatch</para>
		/// </summary>
		/// <example>
		/// Sample usage:
		/// <code>
		/// Halide.StopWatch sw = new Halide.StopWatch();
		/// sw.Start();
		/// 
		/// Trace.Write("Stopwatch", "Process1:" sw.GetTime());
		/// Trace.Write("Stopwatch", "Process2:" sw.GetTime());
		/// sw.Stop()
		/// 
		/// Trace.Write("Stopwatch", "Process 1 &amp; 2:" sw.GetTime());
		/// </code>
		/// </example>
		public string GetTime()
	    {
	        int CurrentTime;
	        float Elasped;

	        CurrentTime =
	            DateTime.Now.Hour * 60 * 60 * 1000 +
	            DateTime.Now.Minute * 60 * 1000 +
	            DateTime.Now.Second * 1000 +
	            DateTime.Now.Millisecond;

	        if (StopTime == 0)
	            Elasped = (CurrentTime - StartTime) / (float)1000;
	        else
	            Elasped = (StopTime - StartTime) / (float)1000;
	        return Elasped.ToString();
		}

	// Outer Identify class
	}

// Outer namespace
}